import { GSprite } from "../../../../com/mui/controls/GSprite";
import { CursorManager } from "../../manager/CursorManager";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { SWFInfo } from "../../../../com/gengine/resource/info/SWFInfo";
import { ExplorerInfo } from "../../model/ExplorerInfo";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
type int = number;
//class EggItem
    
    export  class EggItem extends GSprite
    {
        constructor()
        {
            super();
            this.init();
            addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onEggItemClickHandler);
            addEventListener(flash.events.MouseEvent.MOUSE_MOVE, this.onEggItemRollOverHandler);
            addEventListener(flash.events.MouseEvent.ROLL_OUT, this.onEggItemRollOutHandler);
            addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onEggItemMouseUpHandler);
            return;
        }

        /* internal  */onEggItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.overTest()) 
            {
                CursorManager.showCursor(CursorManager.HitEggDown);
            }
            else 
            {
                CursorManager.hideCursor();
            }
            return;
        }

        /* internal  */onEggItemRollOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.overTest()) 
            {
                CursorManager.showCursor(CursorManager.HitEggOver);
            }
            else 
            {
                CursorManager.hideCursor();
            }
            return;
        }

        /* internal  */onEggItemRollOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            CursorManager.hideCursor();
            return;
        }

        /* internal  */onEggItemMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.overTest()) 
            {
                CursorManager.showCursor(CursorManager.HitEggOver);
            }
            else 
            {
                CursorManager.hideCursor();
            }
            return;
        }

        public overTest(): Boolean
        {
            var loc1=false;
            if (this.mouseX >= 10 && this.mouseX <= 100 && this.mouseY >= 10 && this.mouseY <= 115) 
            {
                loc1 = true;
            }
            return loc1;
        }

        public get amount(): int
        {
            if (this._info) 
            {
                return this._info.amount;
            }
            return 0;
        }

        public get cost(): int
        {
            if (this._info) 
            {
                return this._info.cost;
            }
            return 0;
        }

        /* internal  */init(): void
        {
            this._eggBg = ObjCreate.createBitmap(null, 0, 0, this);
            this._eggStrBmp = ObjCreate.createBitmap(null, 22, 50, this);
            var loc1=new GTextFormat("", 20, 65280, null, null, null, null, null, flash.text.TextFormatAlign.RIGHT);
            this._priceTxt = ObjCreate.createGTextField("", 0, 50, 55, 30, this, loc1);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._eggBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.goldEgg);
            if (this._info && GlobalClass.hasRes("breakEggStr_" + this._info.amount)) 
            {
                this._eggStrBmp.bitmapData = GlobalClass.getBitmapData("breakEggStr_" + this._info.amount);
            }
            return;
        }

        /* internal  */setResVisible(arg1: Boolean): void
        {
            this._eggBg.visible = arg1;
            return;
        }

        /* internal  */playerMovie(): void
        {
            if (this._mc != null) 
            {
                if (!this._isPlaying) 
                {
                    this._isPlaying = true;
                    addChildAt(this._mc, 0);
                    this._mc.gotoAndStop(1);
                    this._mc.play();
                    this._mc.addEventListener(flash.events.Event.ENTER_FRAME, this.onEnterFrameHandler);
                }
            }
            else 
            {
                LoaderManager.instance.load("eggBreaked.swf", this.onLoaded);
            }
            return;
        }

        /* internal  */onLoaded(arg1: SWFInfo): void
        {
            this._isPlaying = true;
            this._mc = arg1.clip;
            this._mc.x = -140;
            this._mc.y = -60;
            addChildAt(this._mc, 0);
            this._mc.addEventListener(flash.events.Event.ENTER_FRAME, this.onEnterFrameHandler);
            this._mc.play();
            return;
        }

        /* internal  */onEnterFrameHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._mc && this._mc.currentFrame == this._mc.totalFrames) 
            {
                this._isPlaying = false;
                this._mc.stop();
                this._mc.removeEventListener(flash.events.Event.ENTER_FRAME, this.onEnterFrameHandler);
                if (this._mc.parent) 
                {
                    this._mc.parent.removeChild(this._mc);
                }
                this.setResVisible(true);
            }
            return;
        }

        public updateItemInfo(arg1: ExplorerInfo): void
        {
            this._info = arg1;
            if (arg1.cost > 0) 
            {
                this._priceTxt.text = arg1.cost + "";
            }
            else 
            {
                this._priceTxt.text = "";
            }
            LoaderHelp.addResCallBack(ResFileConst.BreakEgg, this.onResLoaded);
            return;
        }

        public itemClicked(): void
        {
            this.playerMovie();
            this.setResVisible(false);
            return;
        }

        public set isClick(arg1: Boolean)
        {
            this._isClick = arg1;
            return;
        }

        public get isClick(): Boolean
        {
            return this._isClick;
        }

        /* internal */ /* var */_eggBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_eggStrBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_info: ExplorerInfo;

        /* internal */ /* var */_priceTxt: GTextFiled;

        /* internal */ /* var */_mc: Object /* flash.display.MovieClip */;

        /* internal */ /* var */_isPlaying: Boolean=false;

        /* internal */ /* var */_isClick: Boolean=false;
    }
